CREATE
OR REPLACE PROCEDURE tbjdfxpg_insert_tbqkzj(p_phid IN NUMBER) 
AS 
    jh_phid BIGINT;  -- 跟踪项目计划的phid
    project_addr VARCHAR(255);
    ss_org BIGINT;
BEGIN

   -- 查找跟踪项目计划的phid
    SELECT pr.phid,pr.user_xmszd,pr.user_yzdwssjt INTO jh_phid,project_addr,ss_org
    FROM p_form_tbjdfxpg_m jd-- 投标阶段评估
    LEFT JOIN crm3_tend_chk_m tbch on tbch.phid = jd.u_djly --投标策划  
    LEFT JOIN crm3_advance_project pr on pr.phid=tbch.user_djly
    WHERE jd.phid = p_phid;

    INSERT INTO crm3_tend_analy(
        phid,
        user_xmszd,
        phid_pc,
        phid_org,
        user_djly,
        bill_no,
        user_xmmc,
        user_ywlb,
        user_bdmc,
        user_scfw,
        user_sccyllb,
        user_hylb,
        user_ejhylb,
        user_xmms,
        user_s,
        user_cs,
        user_qx,
        user_gzjb,
        user_yzdw,
        user_tbdw,
        user_tbsj,
        user_tbje,
        user_tbbzje,
        user_tbr,
        bill_dt,
        app_status,
        ng_insert_dt,
        ng_update_dt,
        user_zbjg,
        user_bz,
        --
        bill_name,
        tend_address,
        tend_result,
        tend_explain,
        control_prc,
        final_prc,
        remarks,
        asr_flag,
        wf_flag,
        arc_flag,
        level_code,
        print_count,
        bill_type,
        user_type,
        py,
        ng_record_ver,
        creator,
        editor,
        cur_orgid,
        phid_sourcemid,
        item_resource,
        ng_phid_cu,
        ng_phid_bp,
        ng_phid_ui_scheme,
        ng_phid_original,
        ng_orgid_original,
        ng_sv_search_key,
        ng_sd_search_key,
        ng_share_sign,
        isimport,
        ng_write_source,
        imp_info,
        ng_phid_org,
        user_ssjt,
        phid_schemeid
    )
    SELECT
        seq_auto_phid_tbjdfxpg_to_tbqkzj.nextval,
        project_addr,
        jh_phid,
        phid_org,
        p_phid,
        bill_no,
        project_name,
        user_yelb,
        user_bdmc,
        user_scfw,
        user_sccyllb,
        user_hylb,
        user_ejhylb,
        user_xmms,
        phid_province,
        phid_city,
        phid_region,
        user_gzjb,
        user_yzdw,
        user_tbdw,
        user_tbsj,
        user_tzje,
        user_sjbzjje,
        phid_tbpsn,
        TRUNC(SYSDATE),
        0,
        TRUNC(SYSDATE),
        TRUNC(SYSDATE),
        user_tzje,
        6870000000000046,
        --
        '',
        '',
        1,
        '',
        0.000000000000000,
        0.000000000000000,
        '',
        0,
        null,
        null,
        0,
        0,
        '',
        '',
        null,
        1,
        0,
        0,
        1,
        0,
        '',
        1,
        0,
        0,
        0,
        0,
        '10',
        '1',
        5,
        0,
        null,
        '',
        phid_org,
        ss_org,
        6870000000000039
    FROM crm3_advance_project
    WHERE phid = jh_phid;
    commit;
    EXCEPTION 
    WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('插入失败，错误信息：' || SQLERRM);
    RAISE;
    ROLLBACK;
END tbjdfxpg_insert_tbqkzj;